package com.siwei.mes.entity.vo;

import com.siwei.mes.entity.experiment.Experiment;
import com.siwei.mes.enums.CheckTypeEnum;
import com.siwei.mes.enums.CreateTypeEnum;
import com.siwei.mes.enums.EnturstReasonEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.Set;

/**
 * 创建原材料试验委托
 *
 * @Description: 创建原材料试验委托
 * @Version: 1.0
 * @author: mlchen
 * @date: 2024/9/11 09:14
 */
@Data
public class CreateMaterialsExperimentVo {
    /**
     * 1-水泥 2-粉煤灰 3-矿渣粉 4-粗骨料 5-细骨料 6-外加剂 7-混凝土
     */
    @NotNull(message = "试验委托类型为空")
    @ApiModelProperty(value = "1-水泥 2-粉煤灰 3-矿渣粉 4-粗骨料 5-细骨料 6-外加剂 7-混凝土", name = "experimentType")
    private Integer experimentType;

    @NotNull(message = "检查类型为空")
    @ApiModelProperty(value = "检查类型 1-快检 2-批检")
    private Integer checkType;

    @NotBlank(message = "委托单位为空")
    @ApiModelProperty(value = "委托单位")
    private String experimentCompany;

    @NotBlank(message = "委托部门为空")
    @ApiModelProperty(value = "委托部门")
    private String experimentDept;

    @NotBlank(message = "委托人名称为空")
    @ApiModelProperty(value = "委托人名称", name = "entrustPersonName")
    private String entrustPersonName;

    @ApiModelProperty(value = "联系电话")
    private String phone;

    @NotNull(message = "材料id为空")
    @ApiModelProperty(value = "规格id  pk_materials_spec_config 表的id")
    private Long specId;

    @NotNull(message = "物料id为空")
    @ApiModelProperty(value = "pk_materials表主键ID")
    private String materialsId;

    @NotNull(message = "物料名称为空")
    @ApiModelProperty(value = "物料名称")
    private String matterName;

    @NotNull(message = "物料规格为空")
    @ApiModelProperty(value = "物料规格")
    private String matterSpecs;

    @ApiModelProperty(value = "试验项目数组")
    @NotNull(message = "请选择试验项目")
    private Set<String> testProjectCodeList;

    @NotNull(message = "预报吨位为空")
    @ApiModelProperty(value = "预报吨位")
    private Double forecastNumber;

    @NotBlank(message = "生产厂家为空")
    @ApiModelProperty(value = "生产厂家")
    private String factory;

    @ApiModelProperty(value = "生产厂家简称")
    private String factoryCalled;

    @NotBlank(message = "供应商为空")
    @ApiModelProperty(value = "供应商")
    private String supplierCompanyName;

    @ApiModelProperty(value = "供应商简称")
    private String supplyCompanyCalled;

    @NotNull(message = "委托时间为空")
    @ApiModelProperty(value = "委托时间")
    private Date entrustTime;

    /**
     * 组装试验委托信息
     *
     * @param createMaterialsExperimentVo
     * @return
     */
    public static Experiment payloadExperiment(CreateMaterialsExperimentVo createMaterialsExperimentVo, Double checkThreshold) {
        Experiment experiment = new Experiment();
        experiment.setCheckType(createMaterialsExperimentVo.getCheckType());
        experiment.setExperimentType(createMaterialsExperimentVo.getExperimentType());
        experiment.setEntrustPersonName(createMaterialsExperimentVo.getEntrustPersonName());
        experiment.setEntrustTime(createMaterialsExperimentVo.getEntrustTime());
        experiment.setMoldingTime(createMaterialsExperimentVo.getEntrustTime());
        experiment.setBehalfNumber(checkThreshold);
        experiment.setSpecId(createMaterialsExperimentVo.getSpecId());
        experiment.setFactory(createMaterialsExperimentVo.getFactory());
        experiment.setSupplyCompanyName(createMaterialsExperimentVo.getSupplierCompanyName());
        experiment.setExperimentCompany(createMaterialsExperimentVo.getExperimentCompany());
        experiment.setExperimentDept(createMaterialsExperimentVo.getExperimentDept());
        experiment.setPhone(createMaterialsExperimentVo.getPhone());
        experiment.setCreateCheckType(CheckTypeEnum.DEFAULT_CHECK.getCode());
        experiment.setCreateType(CreateTypeEnum.NEW_CHECK.getCode());
        experiment.setEntrustReasonCode(EnturstReasonEnum.CJ.getCode());
        experiment.setEntrustReasonName(EnturstReasonEnum.CJ.getName());
        experiment.setMaterialsId(createMaterialsExperimentVo.getMaterialsId());
        experiment.setMatterName(createMaterialsExperimentVo.getMatterName());
        experiment.setMatterSpecs(createMaterialsExperimentVo.getMatterSpecs());
        experiment.setSupplyCompanyCalled(createMaterialsExperimentVo.getSupplyCompanyCalled());
        return experiment;
    }
}
